package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppBanners;
import com.ruoyi.app.service.IAppBannersService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * bannerController
 *
 * @author jiang
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/app/banners")
public class AppBannersController extends BaseController {
    @Autowired
    private IAppBannersService appBannersService;

    /**
     * 查询banner列表
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppBanners appBanners) {
        startPage();
        List<AppBanners> list = appBannersService.selectAppBannersList(appBanners);
        return getDataTable(list);
    }

    /**
     * 导出banner列表
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:export')")
    @Log(title = "banner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppBanners appBanners) {
        List<AppBanners> list = appBannersService.selectAppBannersList(appBanners);
        ExcelUtil<AppBanners> util = new ExcelUtil<AppBanners>(AppBanners.class);
        util.exportExcel(response, list, "banner数据");
    }

    /**
     * 获取banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appBannersService.selectAppBannersById(id));
    }

    /**
     * 新增banner
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:add')")
    @Log(title = "banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppBanners appBanners) {
        return toAjax(appBannersService.insertAppBanners(appBanners));
    }

    /**
     * 修改banner
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:edit')")
    @Log(title = "banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppBanners appBanners) {
        return toAjax(appBannersService.updateAppBanners(appBanners));
    }

    /**
     * 删除banner
     */
    @PreAuthorize("@ss.hasPermi('camera:banners:remove')")
    @Log(title = "banner", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appBannersService.deleteAppBannersByIds(ids));
    }
}
